import type {Rule} from 'ant-design-vue/es/form'
import {checkPhone, otwoDecimal, chenkInteger} from '@/utils/check'
// 租客预定的表单校验
export const rules: {
	[key: string | number]: any
} = {
	bookType: [
		{
			required: true,
			message: '请选择支付方式'
		}
	],
	houseAddress: [
		{
			required: true,
			message: '请选择房源地址'
		}
	],
	name: [
		{
			required: true,
			message: '请输入姓名'
		}
	],
	phone: [
		{
			required: true,
			validator: async (_rule: Rule, value: string) => {
				if (!value) {
					return Promise.reject('手机号不能为空')
				} else if (!checkPhone.test(value)) {
					return Promise.reject('手机号格式不正确')
				} else {
					return Promise.resolve()
				}
			}
		}
	],
	moneyType: [
		{
			required: true,
			message: '请选择收支类型'
		}
	],
	money: [
		{
			required: true,
			validator: async (_rule: Rule, value: string) => {
				if (!value || !otwoDecimal.test(value)) {
					return Promise.reject('房间底价不能为0')
				} else {
					return Promise.resolve()
				}
			}
		}
	],
	signDate: [
		{
			required: true,
			message: '请选择最晚签约日期'
		}
	],
	contractMonth: [
		{
			required: true,
			message: '请选择预计租住年限'
		}
	]
}
// 租客合同的表单校验
export const tenantRules: {
	[key: string | number]: any
} = {
	houseId: [
		{
			required: true,
			message: '请选择房源地址'
		}
	],
	name: [
		{
			required: true,
			message: '请输入姓名'
		}
	],
	phone: [
		{
			required: true,
			validator: async (_rule: Rule, value: string) => {
				if (!value) {
					return Promise.reject('请输入手机号')
				} else if (!checkPhone.test(value)) {
					return Promise.reject('手机号格式不正确')
				} else {
					return Promise.resolve()
				}
			}
		}
	],
	nationality: [
		{
			required: true,
			message: '请选择国家(地区)'
		}
	],
	emergencyName: [
		{
			required: true,
			message: '请输入紧急联系人姓名'
		}
	],
	emergencyPhone: [
		{
			required: true,
			message: '请输入紧急联系人电话'
		}
	],
	price: [
		{
			required: true,
			validator: async (_rule: Rule, value: string) => {
				if (!Number(value) || !otwoDecimal.test(value)) {
					return Promise.reject('金额>0且只能保留1到2位小数')
				} else {
					return Promise.resolve()
				}
			}
		}
	],
	deposit: [
		{
			validator: async (_rule: Rule, value: string) => {
				if (!Number(value) || !otwoDecimal.test(value)) {
					return Promise.reject('金额>0且只能保留1到2位小数')
				} else {
					return Promise.resolve()
				}
			}
		}
	],
	payPatternValue: [
		{
			required: true,
			validator: async (_rule: Rule, value: string) => {
				if (value === '') {
					return Promise.reject('收租日不能为空')
				} else if (!chenkInteger.test(value)) {
					return Promise.reject('收租日只能为整数')
				} else {
					return Promise.resolve()
				}
			}
		}
	],
	signTime: [
		{
			required: true,
			message: '请选择签约日期'
		}
	]
}
